home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PRIVATE.ZIP / _ADDWIN.C < prev    next >
Text File  |  1992-11-21  |  3KB  |  100 lines

  1. #ifndef NO_MEMORY_H
  2. #include <memory.h>
  3. #endif
  4. #define        CURSES_LIBRARY  1
  5. #include <curses.h>
  6.  
  7. #ifdef REGISTERWINDOWS
  8. #ifndef NDEBUG
  9. char *rcsid__addwin = "$Header: c:/curses/private/RCS/_addwin.c%v 2.0 1992/11/15 03:24:18 MH Rel $";
  10. #endif
  11.  
  12.  
  13.  
  14.  
  15. /*man-start*********************************************************************
  16.  
  17.   PDC_addwin() - adds window
  18.  
  19.   PDCurses Description:
  20.        This routine adds the passed window pointer after the specified
  21.        window.  If the specified window is NULL, then the passed
  22.        window pointer is inserted first in the list.
  23.  
  24.        If the 'after' window is not on the visible list, then 'win'
  25.        will be added to the end of the list.
  26.  
  27.   PDCurses Return Value:
  28.        This routine will return OK upon success and otherwise ERR will be
  29.        returned.
  30.  
  31.   PDCurses Errors:
  32.        An error will occur if we are unable to allocate a new WINDS
  33.        structure.
  34.  
  35.   Portability:
  36.        PDCurses        int     PDC_addwin( WINDOW* win, WINDOW* after );
  37.  
  38. **man-end**********************************************************************/
  39.  
  40. int    _addwin(WINDOW *win, WINDOW *after)
  41. {
  42. extern void*   (*mallc)( size_t );
  43. extern void*   (*callc)( size_t, size_t );
  44. extern void    (*fre)( void* );
  45.  
  46.        WINDS  *root = _cursvar.visible;
  47.        WINDS  *wlst = PDC_findwin(after);
  48.        WINDS  *new  = (*mallc)(sizeof(WINDS));
  49.  
  50.        if (new == (WINDOW *)NULL)
  51.                return( ERR );
  52.  
  53.        PDC_rmwin(win);
  54.        memset(new, 0, sizeof(WINDS));
  55.        new->w = win;
  56.        if (wlst == (WINDS *)NULL)
  57.        {
  58.                if (root == (WINDS *)NULL)
  59.                        _cursvar.visible = new;
  60.                else
  61.                {
  62.                        root->tail->next = new;
  63.                        new->prev = root->tail;
  64.                        root->tail = new;
  65.                }
  66.        }
  67.        else
  68.        {
  69.                if (root->next == NULL)
  70.                {
  71.                        root->next = new;
  72.                        new->prev = root;
  73.                }
  74.                else
  75.                if (wlst == root->tail)
  76.                {
  77.                        root->tail->next = new;
  78.                        new->prev = root->tail;
  79.                        root->tail = new;
  80.                }
  81.                else
  82.                {
  83.                        new->prev = wlst;
  84.                        new->next = wlst->next;
  85.                        if (wlst->next == NULL)
  86.                        {
  87.                                wlst->next = new;
  88.                                root->tail = new;
  89.                        }
  90.                        else
  91.                        {
  92.                                wlst->next->prev = new;
  93.                                wlst->next = new;
  94.                        }
  95.                }
  96.        }
  97.        return( OK );
  98. }
  99. #endif
  100.